<template>
  <view class="cart-container" v-if="cart.length!==0">
    <!-- 收货地址组件 -->
    <my-address></my-address>
    <!-- 收货地址组件结束 -->
      <view class="cart-title">
        <uni-icons type="shop" size="18"></uni-icons>
        <text class="cart-text">购物车</text>
      </view>
      
      <!-- 循环渲染购物车的数据 -->
      <uni-swipe-action>
         <block v-for="item,i in cart" :key="i">
        <uni-swipe-action-item :right-options="options" @click="swipeItemClickHandler(item)">
         
            <my-goods :showNumberBox="true" :goods="item" :showRadio="true" @radio-change="radioChangeHandler" @num-change="numChangeHandler"></my-goods>
        
        </uni-swipe-action-item>
          </block>
      </uni-swipe-action>
     
     <!-- 使用自定义的结算组件 -->
     <my-settle></my-settle>
     <!-- 使用自定义的结算组件结束 -->
  </view>
  <view class="empty-cart" v-else>
    <text>空空如也~</text>
  </view>
</template>

<script>
  import { mapState, mapMutations } from 'vuex'
  import badgeMix from '../../mixins/tabbar-badge.js'
  export default {
    mixins:[badgeMix],
    computed:{
      ...mapState('m_cart',['cart'])
    },
    data() {
      return {
        options:[{
          text:'删除',
          style:{
            backgroundColor:'#FF4536'
          }
        }]
      }
    },
    methods:{
      ...mapMutations('m_cart',['updateGoodsState','addNumGoodsState','removeItemById']),
      radioChangeHandler(e){
        console.log(e)
        this.updateGoodsState(e)
      },
      numChangeHandler(e){
        console.log(e)
        this.addNumGoodsState(e)
      },
      swipeItemClickHandler(item){
        console.log(item);
        this.removeItemById(item.goods_id)
      }
    }
  }
</script>

<style lang="scss">
  .cart-container{
    padding-bottom: 50px;
  }
.cart-title{
  height: 40px;
  display: flex;
  align-items: center;
  padding-left: 10rpx;
  border-bottom: 2rpx solid #f5f5f5;
  .cart-text{
    padding: 0 20rpx;
    font-size: 32rpx;
    
  }
}
.empty-cart{
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
